﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CheckOutRepository.cs" company="DST Nexdox">
//   Copyright (c) DST Nexdox. All rights reserved.
// </copyright>
// <summary>
//   Defines the CheckOutRepository type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace UnityRepository.Repositories
{
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using EFRepository;
  using Entities;
  using UnityRepository.Contexts;
  using UnityRepository.Interfaces;

  public class CheckOutRepository : BaseEfRepository<CheckOut>, ICheckOutRepository
  {
    public CheckOutRepository(String connectionString)
      : base(new UnityDbContext(connectionString))
    {
    }

    public CheckOut GetCheckOut(String documentId)
    {
      return (from e in Entities
              where e.Document.DocumentId == documentId && e.CheckOutBy != null
              select e).FirstOrDefault();
    }

    public List<CheckOut> GetCheckOutsForCart(String cartId)
    {
      return (from checkOut in Entities where checkOut.Document.CartItems.Any(ci => ci.CartId == cartId) select checkOut).ToList();
    }
  }
}
